"""
金融数据模型
"""
from sqlalchemy import Column, String, Float, DateTime, ForeignKey, Integer
from sqlalchemy.orm import relationship
from .base import Base
import datetime

class SpotData(Base):
    """现货数据模型"""
    __tablename__ = 'spot_data'
    
    id = Column(Integer, primary_key=True)
    symbol = Column(String(32), unique=True, nullable=False)
    name = Column(String(64))
    exchange = Column(String(64))
    listing_date = Column(DateTime)
    update_time = Column(DateTime, default=datetime.datetime.now)
    
    daily_data = relationship("SpotDailyData", back_populates="spot")

class SpotDailyData(Base):
    """现货日线数据模型"""
    __tablename__ = 'spot_daily_data'
    
    id = Column(Integer, primary_key=True)
    spot_id = Column(Integer, ForeignKey('spot_data.id'))
    date = Column(DateTime)
    open = Column(Float)
    high = Column(Float)
    low = Column(Float)
    close = Column(Float)
    volume = Column(Float)
    turnover = Column(Float)
    update_time = Column(DateTime, default=datetime.datetime.now)
    
    spot = relationship("SpotData", back_populates="daily_data")

class ForexData(Base):
    """外汇数据模型"""
    __tablename__ = 'forex_data'
    
    id = Column(Integer, primary_key=True)
    symbol = Column(String(32), unique=True, nullable=False)
    name = Column(String(64))
    currency_type = Column(String(32))
    update_time = Column(DateTime, default=datetime.datetime.now)
    
    daily_data = relationship("ForexDailyData", back_populates="forex")

class ForexDailyData(Base):
    """外汇日线数据模型"""
    __tablename__ = 'forex_daily_data'
    
    id = Column(Integer, primary_key=True)
    forex_id = Column(Integer, ForeignKey('forex_data.id'))
    date = Column(DateTime)
    open = Column(Float)
    high = Column(Float)
    low = Column(Float)
    close = Column(Float)
    update_time = Column(DateTime, default=datetime.datetime.now)
    
    forex = relationship("ForexData", back_populates="daily_data")